package registnet.records.source;

import java.util.List;

import registnet.records.Curriculum;
import registnet.records.CurriculumCourse;
import registnet.records.DegreeProgram;

public class CurriculumSource {

	private String curriculumCode;
	private Curriculum curriculum;
	
	
	/**
	 * Default constructor
	 * 
	 * @param curriculumCode - The code assigned to a curriculum
	 */
	public CurriculumSource(String curriculumCode){
		this.curriculumCode = curriculumCode;
		this.load();
	}
	
	
	/**
	 * Loads data from source 
	 */
	public void load(){
		try{
			registnet.dao.Curriculum DAOCurriculum = new registnet.dao.CurriculumPeer().getCurriculum(curriculumCode);
			List<registnet.dao.CurriculumCourse> DAOCurriculumCourses = new registnet.dao.CurriculumCoursePeer().getCurriculumCourses(DAOCurriculum.getCurriculumId());
			DegreeProgram degreeProgram = new DegreeProgramSource(DAOCurriculum.getDegreeCourse().getDegreeCode()).getDegreeProgram();
			this.curriculum = new Curriculum(this.curriculumCode);
			this.curriculum.setCurriculumName(DAOCurriculum.getCurriculumName());
			this.curriculum.setDegreeProgram(degreeProgram);
			for(int i=0; i<DAOCurriculumCourses.size(); i++){
				registnet.dao.CurriculumCourse DAOCurriculumCourse = DAOCurriculumCourses.get(i);
				CurriculumCourse cc = new CurriculumCourseSource(DAOCurriculumCourse.getCourse().getCourseCode(), this.curriculum, DAOCurriculumCourse.getSemester(), DAOCurriculumCourse.getYear()).getCurriculumCourse();
				this.curriculum.addCourse(cc);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	/**
	 * Gets the curriculum
	 * 
	 * @return	The curriculum
	 */
	public Curriculum getCurriculum(){
		return this.curriculum;
	}
}
